tuenti_lib = {
    onchangepage: new classes_lib.Observer('onChangePage'),
    visual: {
        thumbExp: /^http:\/\/(?:[\w.\-_]+\/){2}((?:[\w\.]+\/){3})[\w.\-_]+\/(.*)$/i,
        thumbServer: 'http://imagenes2.tuenti.net/',
        //info: http://www.tuentiadictos.es/truco-para-ampliar-fotos-de-cualquier-usuario-en-el-nuevo-tuenti/
        thumbUrl: function(url, size) {

            switch(size) {
                case 'verysmall':
                    size = '75/';
                    break;
                case 'small':
                    size = '120/';
                    break;
                case 'big':
                    size = '600/';
                    break;
                case 'medium':
                default:
                    size = '200/';
            }
            
            var mt = this.thumbExp.exec(url);

            if (!mt) return undefined;
            
            return this.thumbServer + mt[1] + size + mt[2];
        }
    },
    config: {
        cfgKey: 'tplus_cfg',
        defaultConfig: {bigAvatar: true, smiley: true, theme: 'normal', javaUpload: false, ads: true, background: 'http://', stats: true, adsInv: true, preview: true},
        get: function() {

            if (this.cache)
                return system_lib.object.clone(this.cache);

            var str = system_lib.storage.get(this.cfgKey);
            var cfg;

            if (str) {
                cfg = JSON.decode(str);

                //Mergeado de configuración entre versiones
                for (var key in this.defaultConfig) {
                    if (typeof cfg[key] == 'undefined') cfg[key] = this.defaultConfig[key];
                }

            }
            else {
                cfg = this.defaultConfig;
            }

            this.cache = cfg;

            return cfg;
        },
        save: function(cfg) {
            if (config_mod) config_mod.onsaveconfig.fire(cfg);
            this.cache = cfg;
            system_lib.storage.set(this.cfgKey, JSON.encode(cfg));
        }
    },
    module: {
        names: {inicio: 'Home', historial: 'Wall',pagina: 'Page', perfil: 'Profile', foto: 'Photo', album: 'Albums', pm: 'Message', gente: 'Search', videos: 'Video', juegos: 'Games', opciones: 'Settings', evento: 'Event', miembros: 'Widget_memberlist'},
        getName: function() {
            return system_lib.url.getParam('m');
        },
        getFunction: function() {
            return system_lib.url.getParam('func');
        }
    }
};

if (!RequestEngine) console.error('error: no se encuentra RequestEngine');

RequestEngine.AJAX.Web2ResponseHandler.ohandle_response = RequestEngine.AJAX.Web2ResponseHandler.handle_response;

RequestEngine.AJAX.Web2ResponseHandler.handle_response = function(response) {
    var result = RequestEngine.AJAX.Web2ResponseHandler.ohandle_response(response);
    if (response.success == true) tuenti_lib.onchangepage.fire(response);
    return result;
}